﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace PortDetection.Class
{
    public class NoticeInfo
    {
        #region 属性
        /// <summary>
        /// 名称
        /// </summary>
        [XmlAttribute("name")]
        public string name { get; set; }

        /// <summary>
        /// 邮箱地址
        /// </summary>
        [XmlAttribute("emailaddress")]
        public string emailaddress { get; set; }

        

        #endregion
    }


    public class XMLFile
    {
        public static string XMLPath { get { return Environment.CurrentDirectory + "\\NoticeInfo.xml"; } }

        /// <summary>
        /// 保存生成XML
        /// </summary>
        /// <param name="strPath">XML路径</param>
        /// <param name="ListInfo">信息列表</param>
        public static void SaveFile(List<NoticeInfo> ListInfo)
        {
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
            ns.Add("", "");
            FileStream fs = new FileStream(XMLPath, FileMode.Create, FileAccess.Write);
            XmlSerializer ResSerializer = new XmlSerializer(typeof(List<NoticeInfo>));
            ResSerializer.Serialize(fs, ListInfo, ns);
            
            fs.Close();
        }

        public static List<NoticeInfo> ReadXMLFile()
        {
            FileStream dfs = new FileStream(XMLPath, FileMode.Open);
            XmlSerializer xs = new XmlSerializer(typeof(List<NoticeInfo>));
            List<NoticeInfo> listPers = xs.Deserialize(dfs) as List<NoticeInfo>;
            dfs.Close();
            return listPers;
        }
    }
}
